package com.gis.dto;

import com.gis.enums.QualityReportEnum;
import lombok.Data;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import static org.apache.commons.lang.StringUtils.capitalize;

@Data
public class RedtideDTO {
    private Integer stationId;
    private Float chla;
    private Float ph;
    private Float dissolvedOxygen;

    public QualityReportEnum getResult() {
        if((ph==null||ph >= 8.12) && (dissolvedOxygen == null||dissolvedOxygen >=10) && (chla==null||chla >= 20)){
            return QualityReportEnum.STATE_HAPPENED;
        }
        return QualityReportEnum.STATE_NOHAPPEN;
    }

    public boolean notNull(){
        return chla!=null&&ph!=null&&dissolvedOxygen!=null;
    }

    public RedtideDTO setParam(String param, Float value, RedtideDTO redtideDTO){
        String methodName = "set" + capitalize(param);
        Method method = null;
        try {
            // set函数反射时要带参数类型
            method = RedtideDTO.class.getMethod(methodName, Float.class);
            method.invoke(redtideDTO, value);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
        return redtideDTO;
    }


}
